package com.corffen.design;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject {
    List<Observer> mObservers = new ArrayList<>();
    private float temperature;
    private float humidity;
    private float degree;

    @Override
    public void addObserver(Observer observer) {
        if (!mObservers.contains(observer)) {
            mObservers.add(observer);
        }
    }

    @Override
    public void removeObserver(Observer observer) {
        if (mObservers.contains(observer)) {
            mObservers.remove(observer);
        }
    }

    @Override
    public void notifyChanged() {
        for (int i = 0; i < mObservers.size(); i++) {
            mObservers.get(i).update(temperature, humidity, degree);
        }
    }

    public void measureWeatherData() {
        notifyChanged();
    }

    public void setWeatherData(float temperature, float humidity, float degree) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.degree = degree;
        measureWeatherData();
    }

}
